#

| Chapter 40 Delayed Execution |

## 40.2 Waiting a Little While: sleep

sleep sleep | The sleep command waits. That's all it does. (GNU versions are usually loaded with features, but the sleep on the disc doesn't do more than the standard version.) So, what good is it?

- A quick-and-dirty reminder service when you don't have leave (48.5). This will print the message `Time to go now....` in 10 minutes (600 seconds):

      ( ) & ;
      % (sleep 600; echo Time to go now....) &

- You can't use at (40.3) and you have to run a job later (say, three hours):

  >     % (sleep 10800; someprog) &

- To watch a program (usually a shell script) that's running in the background and see what processes it runs:

      !!
      % prog &
      [1] 12345
      % sleep 5;ps
        PID TT STAT  TIME COMMAND
      18305 p4 S     0:01 -csh (csh)
      18435 p4 S     0:00 /bin/sh prog
      18437 p4 D     0:00 /bin/sort -r temp
      18438 p4 R     0:00 ps
      % !!;!!;!!;!!;!!
      sleep 5; ps; sleep 5; ps; sleep 5; ps; sleep 5; ps; sleep 5; ps
        PID TT STAT  TIME COMMAND
          ...
          ...5 seconds pass...
        PID TT STAT  TIME COMMAND
          ...

- When you're running a series of commands that could swamp the computer, give it time to catch up. For instance, the mail (1.33) program starts background processes to deliver the mail. If you're sending a bunch of form letters, sleep five or ten seconds after each one:

      foreach
      % foreach name (`cat people`)
      ? formltrprog $name | mail $name
      ? sleep 10
      ? end

  Or, to send print jobs while you're at lunch - but give other people a chance to print between yours:

  >     % lp bigfile1;sleep 600;lp bigfile2;sleep 600;lp bigfile3

- JP

40.1 Off-Peak Job Submission |  | 40.3 The at Command